package spring.test1;

import com.blackhorse.domain.PojoVo;
import com.blackhorse.domain.User;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Demo4_BeanDependencyInject {
    ClassPathXmlApplicationContext applicationContext;

    @Before
    public void setUp() {
        //创建容器时单例bean被创建
        applicationContext = new ClassPathXmlApplicationContext("ioc/applicationContext.xml");
    }

    @Test
    public void testDIByConstructor() {
        User user = applicationContext.getBean("userInjectByConstructor", User.class);
        System.out.println(user);
    }

    @Test
    public void testDIBySetter() {
        User user = applicationContext.getBean("userInjectBySetter", User.class);
        System.out.println(user);
    }

    @Test
    public void testDIBySetterCompelex() {
        PojoVo pojoVo = applicationContext.getBean("pojoVoInjectBySetter", PojoVo.class);
        System.out.println(pojoVo);
    }
}
